"use strict";
/* Controllers */
app.controller("demandListController", ['$scope', '$location', '$rootScope', '$routeParams', 'demandListService', function ($scope, $location, $rootScope, $routeParams, demandListService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.result = {};
    vm.p.clusterName = $routeParams.cluster;
    vm.p.queue= $routeParams.queue;


    var errorFn = function (result) {
        alert(result);
    };

    $scope.listDemand = function () {
        var vm = $scope.vm;
        vm.result.ms = "...";
        var params = {clusterName: vm.p.clusterName, queue: vm.p.queue};
        var procFn = function (response) {
            vm.result.ms = response.ms;
            var data = response.data;
            if (data == null) return;
            vm.result.data = data;
            $('#list_table').bootstrapTable('load', data);
        };
        demandListService.listDemand(params, procFn, errorFn);
    };

    $scope.initializeController = function () {
        vm.result.ms = '';
        var $resultTable = $('#list_table');
        $resultTable.bootstrapTable({
             pageList: [30, 50, 100, 300, 500, 1000], pageSize: 30
        });
        $resultTable.bootstrapTable('hideColumn', 'action');
        $scope.listDemand();
    };

    $scope.initializeController();

}]);


/* Services */
app.service('demandListService', ['ajaxService', function (ajaxService) {

    this.listDemand = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/reci-service/v1/alert_log/listDemand.do", successFunction, errorFunction);
    };

    this.deleteDemand = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/reci-service/v1/alert_log/deleteDemand.do", successFunction, errorFunction);
    };
}]);

function queueTypeFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    switch (value) {
        case 0:
            return "动态";
        case 1:
            return "固定";
        default:
            return "-";
    }
}

function demandIDOptFmt(value, row, index) {
    if (value == null) {
        return "-";
    }
    return [
        '<a href="#/star/order/alert_log_detail/', value,'" target="_blank">', "<u>解决</u>" , '</a>'
    ].join('');
}


